<!DOCTYPE html>
<html>
<head>
  	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>留学生管理系统</title>
	<link rel="stylesheet" href="${path}/css/admin2.css">
	<link rel="stylesheet" href="${path}/css/coursemanage-kb.css">
	<script type="text/javascript" src="${path}/js/jquery.min.js"></script>
</head>
<body>
	<div id="mask"></div>

	<!--header-->
	<div id="header"></div>
	<div id="main">
		<div id="side-menu"></div>
		<div id="container">
            <div id="inner-border">
                <form action="${path}/adminCourseManage/addTerm" type="post">
                    <button type="submit">新增学期</button>
                </form>
                ${message!}
                <table id="termtable">
                    <thead>
                        <tr>
                            <th>学期</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    <#if allTerm?exists>
                    <#list allTerm as r>
                        <tr>
                            <td>${r.termValue!}</td>
                            <td><input id="invalid" type="hidden" value="${r.invalid!}"><input id="current" type="hidden" value="${r.current!}"></td>
                            <td>
                                <a value="${r.id!}" onclick="setCurrent(this)">设为当前学期</a><!-- <button class="delete" type="button" onclick="deleteTerm(this)">删除</button> -->
                                <a value="${r.id!}" type="button" onclick="setInvalid(this)">设为过期学期</a>
                            </td>
                        </tr>
                    </#list>
                    </#if>
                    </tbody>
                </table>
            </div>
		</div>
	</div>
	<script type="text/javascript">
		//function deleteTerm(obj){
		//	var id=obj.value;
		//	window.location.href="${path}/adminCourseManage/deleteTerm?term="+id;
		//}
		function setCurrent(obj){
			var id=obj.value;
			window.location.href="${path}/adminCourseManage/setCurrentTerm?term="+id;
		}
		function setInvalid(obj){
			var id=obj.value;
			window.location.href="${path}/adminCourseManage/setInvalidTerm?term="+id;
		}
        $(document).ready(function(){
            var termtable = $("#termtable tbody tr");
            console.log(termtable);
            for(var tr in termtable){
                var invalid = termtable[tr].children[1].children[0].value;
                var current = termtable[tr].children[1].children[1].value;
		if(invalid == 1){
			termtable[tr].children[1].innerHTML = "已失效";
            	}
		else if(invalid == 0 && current == 1){
			termtable[tr].children[1].innerHTML = "当前学期";
		}
		else if(invalid == 0 && current == 0){
			termtable[tr].children[1].innerHTML = "新学期";
		}
		else{
			termtable[tr].children[1].innerHTML = "状态错误";
		}}
        })
	</script>
	<script type="text/javascript" src="${path}/js/admin-main-appearance.js"></script>

	<!-- DataTables JavaScript -->
	<script src="${path}/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
	<script src="${path}/bower_components/datatables-plugins/api/fnGetHiddenNodes.js"></script>
	<script src="${path}/bower_components/datatables-plugins/api/fnGetTd.js"></script>
	<script src="${path}/bower_components/datatables-plugins/api/fnGetTds.js"></script>
	<script src="${path}/bower_components/datatables-plugins/api/fnGetColumnData.js"></script>
	<script src="${path}/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>

</body>
</html>
